
class Solution:
	def twoSum(self, nums, target):
		"""
			nums为一个数组，求数组中的两个值等于target，
			数组中必有两个值，求出这两个值的位置
		"""
		# for(i = 0; i<len(nums)-1; i++):
		# 	for(j = i+1; j<len(nums); i++):
		# 		if(nums[i]+nums[j] == target):
		# 			return [i, j, nums[i], nums[j]]

		i = 0
		while(i < len(nums)-1):
			j = i+1
			print(j)
			while(j < len(nums)):
				if(nums[i]+nums[j] == target):
					return [i, j, nums[i], nums[j]]
				j = j+1
			i = i+1

	def twoSum2(self, nums, target):
		"""
		时间复杂度为O(n)，先把差值获取到，然后对比剩余数组中的值
		"""
		i = 0
		while(i < len(nums)):
			num2 = target - nums[i]
			num_follew = nums[i+1:]
			if num2 in num_follew:
				return [i, num_follew.index(num2)+i+1]
			i = i+1



sol = Solution()
nums, target = [3,6,8,9], 15
res = sol.twoSum2(nums, target)
print(res)